//
//  ViewController.m
//  dwl
//
//  Created by dllo on 15/11/17.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "ViewController.h"
#import <Masonry.h>
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
#if 0
    //创建一个view
    UIView *view = [UIView new];
    //颜色
    view.backgroundColor = [UIColor yellowColor];
    //
    [self.view addSubview:view];
    
    //300*300居中显示的矩形
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.view);
        make.size.mas_equalTo(CGSizeMake(300, 300));
        
    }];
    
//    make方法只负责增加新的约束,但是不能同时出现两条针对同一对象的约束,否则会报错
//    update方法针对上面的情况,会更新约束,以确保不会出现两条相同的约束
//    remake方法会清除之前所有约束,并重新创建一次
#endif
    
    
#if 0
//    创建一个view略小于上级视图
    UIView *view1 = [UIView new];
    view1.backgroundColor = [UIColor yellowColor];
//    一定要先将view贴到上级视图上再创建约束, 否则会报错
    [self.view addSubview:view1];
    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.view.mas_top).with.offset(15);
//        make.left.equalTo(self.view).with.offset(15);
//        make.bottom.equalTo(self.view).with.offset(-15);
//        make.right.equalTo(self.view).with.offset(-15);
//        make.top.and.left.and.bottom.and.right.equalTo(self.view).insets(UIEdgeInsetsMake(15, 15, 15, 15));

        make.edges.equalTo(self.view).with.insets(UIEdgeInsetsMake(15, 15, 15, 15));

        
    }];
#endif
    
//    两个高度为150的view 居中并且等宽, 等间距, 宽度计算
    UIView *view1 = [UIView new];
    view1.backgroundColor = [UIColor redColor];
    [self.view addSubview:view1];
    UIView *view2 = [UIView new];
    view2.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:view2];
    
    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.equalTo(self.view.mas_centerY);
        make.left.equalTo(self.view).with.offset(15);
        make.right.equalTo(view2.mas_left).with.offset(-15);
        make.height.mas_equalTo(150);
        make.width.equalTo(view2);
        
    }];
    [view2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(self.view.mas_centerY);
        make.left.equalTo(view1.mas_right).with.offset(15);
        make.right.equalTo(self.view).with.offset(-15);
        make.height.mas_equalTo(150);
        make.width.equalTo(view1);
        
    }];

    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
